import React from "react";
import { Button, Space} from "antd";
import { BasicTable } from "@antd/index";
import type { TableProps } from "antd";
import type { AccountTable } from "./index.d";
import dayjs from "dayjs";
export const statusMap: any = {
  0: "禁用",
  1: "启用",
};
export const sexMap: any = {
  0: "男",
  1: "女",
};
const Table = React.memo(
  ({ tableData, handleAction, tablePage, setTablePage }: any) => {
    console.log("Table组件");
    const handleChangeTablePage = ({ current, pageSize }: any) => {
      setTablePage({ ...tablePage, current, pageSize });
    };
    const columns: TableProps<AccountTable>["columns"] = [
      {
        title: "序号",
        dataIndex: "index",
        key: "index",
        render: (_text, _record, index) => renderIndex(index, tablePage),
      },
      {
        title: "用户名",
        dataIndex: "username",
        key: "username",
      },
      {
        title: "角色名",
        dataIndex: "roleName",
        key: "roleName",
      },
      {
        title: "所属部门",
        dataIndex: "department",
        key: "department",
      },
      {
        title: "手机号",
        dataIndex: "phone",
        key: "phone",
      },
      {
        title: "状态",
        dataIndex: "status",
        key: "status",
      },
      {
        title: "创建时间",
        dataIndex: "createTime",
        key: "createTime",
        render: (_text) => dayjs(_text).format("YYYY-MM-DD HH:mm:ss"),
      },
      {
        title: "更新时间",
        dataIndex: "updateTime",
        key: "updateTime",
        render: (_text) => dayjs(_text).format("YYYY-MM-DD HH:mm:ss"),
      },
      {
        title: "操作",
        key: "action",
        render: (_text, record: any) => {
          return (
            <Space>
              <Button
                type="link"
                onClick={() => handleAction({ type: "update", record })}
              >
                编辑
              </Button>
              <Button
                type="link"
                onClick={() => handleAction({ type: "detail", record })}
              >
                详情
              </Button>
              <Button
                type="link"
                onClick={() => handleAction({ type: "delete", record })}
              >
                删除
              </Button>
              <Button
                type="link"
                onClick={() => handleAction({ type: "disabled", record })}
              >
                {record.status === 0 ? "启用" : "禁用"}
              </Button>
            </Space>
          );
        },
      },
    ];
    return (
      <BasicTable
        columns={columns}
        dataSource={tableData}
        tablePage={tablePage}
        onChange={handleChangeTablePage}
      />
    );
  }
);
export default Table;
